package com.lib.common.widget.dialog.share

import android.content.Context
import com.lib.common.R
import com.lib.common.databinding.ItemShareListBinding
import com.lib.framework.widget.adapter.BaseBindingAdapter

/**
 * 分享列表的 adapter
 *
 * @author keanbin
 */
class ShareListAdapter(context: Context, dataList: MutableList<ShareItem>) :
        BaseBindingAdapter<ShareItem, ItemShareListBinding>(context, dataList) {

    /**
     * 点击监听器
     */
    var mOnClickListener: OnClickListener? = null

    override fun getLayoutResId(viewType: Int): Int {
        return R.layout.item_share_list
    }

    override fun onBindItem(binding: ItemShareListBinding?, item: ShareItem, position: Int) {
        if (binding == null) {
            return
        }

        binding.tvName.text = item.name
        binding.ivIcon.setImageResource(item.iconResId)

        binding.root.setOnClickListener {
            mOnClickListener?.onClick(item, position)
        }
    }

    /**
     * 点击监听器
     */
    interface OnClickListener {

        /**
         * 点击回调
         */
        fun onClick(item: ShareItem, position: Int)
    }
}